package com.cloud.yangfeiself.config;


import com.cloud.yangfeiself.filter.JwtFilter;
import com.cloud.yangfeiself.util.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class SpringContextConfig implements WebMvcConfigurer {


    @Bean
    public FilterRegistrationBean<JwtFilter> filterRegistrationBean(@Autowired JwtUtil jwtUtil){
        FilterRegistrationBean<JwtFilter> filterRegistrationBean = new FilterRegistrationBean<>();
        filterRegistrationBean.setFilter(new JwtFilter(jwtUtil));
        List<String> urls = new ArrayList<>();
        urls.add("/auth/*");
        filterRegistrationBean.setUrlPatterns(urls);
        return filterRegistrationBean;
    }
}
